﻿package plugin.npcDialog.ui.panels.boss
{
    import cmd.*;
    import com.core.*;
    import com.greensock.*;
    import consts.*;
    import flash.events.*;
    import flash.filters.*;
    import manager.*;
    import morn.core.handlers.*;
    import morn.core.utils.*;
    import pluginfw.nio.*;
    import uiresource.npcdialogs.*;
    import view.*;

    public class WzadCtrl extends WzadUI implements INpcDialogContent
    {
        private var tweenMax:TweenMax;
        private var _data:Object;
        private var deliver:Object;

        public function WzadCtrl()
        {
            return;
        }// end function

        public function close() : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            this.removeTween();
            return;
        }// end function

        public function removeTween() : void
        {
            if (this.tweenMax)
            {
                this.tweenMax.kill();
                this.tweenMax = null;
                ObjectUtils.clearFilter(goumai, GlowFilter);
            }
            return;
        }// end function

        public function show(param1:Object, param2:Object) : void
        {
            this._data = param1;
            this.updatebag();
            var _loc_3:* = UserData.getOnlineData("guide");
            if (int(_loc_3[GuideType.GUIDE_AD]) == 1 && int(_loc_3[GuideType.GUIDE_AD1]) == 0)
            {
                GuideView.getInstance().doGuide(GuideType.GUIDE_AD1);
            }
            else if (int(_loc_3[GuideType.GUIDE_AD2]) == 1 && int(_loc_3[GuideType.GUIDE_AD3]) == 0)
            {
                GuideView.getInstance().doGuide(GuideType.GUIDE_AD3);
            }
            GuideView.getInstance().doNextGuide(GuideType.GUIDE_AD4);
            GuideView.getInstance().doNextGuide(GuideType.GUIDE_AD5);
            GuideView.getInstance().doNextGuide(GuideType.GUIDE_AD6);
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            label_jinru.addEventListener(MouseEvent.CLICK, this.clickHandler);
            ModelProxy.change("guideitem", "guideid" + GuideType.GUIDE_AD1, label_jinru);
            ModelProxy.change("guideitem", "guideid" + GuideType.GUIDE_AD3, label_jinru);
            ModelProxy.change("guideitem", "guideid" + GuideType.GUIDE_AD4, label_jinru);
            ModelProxy.change("guideitem", "guideid" + GuideType.GUIDE_AD5, label_jinru);
            ModelProxy.change("guideitem", "guideid" + GuideType.GUIDE_AD6, label_jinru);
            return;
        }// end function

        private function toGm() : void
        {
            ModelProxy.change("plugin", "open", {target:"goddess"});
            return;
        }// end function

        protected function clickHandler(event:MouseEvent) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Output = null;
            ModelProxy.change("guide", "hide", GuideType.GUIDE_AD1);
            ModelProxy.change("guide", "hide", GuideType.GUIDE_AD3);
            ModelProxy.change("guide", "hide", GuideType.GUIDE_AD4);
            ModelProxy.change("guide", "hide", GuideType.GUIDE_AD5);
            ModelProxy.change("guide", "hide", GuideType.GUIDE_AD6);
            var _loc_2:* = UserData.getBagData("bonus");
            if (_loc_2 < 200 && ModelProxy.getValue("data", "openday") >= 2)
            {
                WarningManager.show(31, ["礼券"]);
            }
            else
            {
                this.deliver = ConfigDictionary.data.deliver[1104];
                for each (_loc_3 in this.deliver)
                {
                    
                    if (_loc_3.stageid == 1103)
                    {
                        if (_loc_3.level > UserData.getUserData("level"))
                        {
                            WarningManager.show(32, [_loc_3.level]);
                            return;
                        }
                    }
                }
                this.deliver = ConfigDictionary.data.deliver[this._data.npcid][0];
                _loc_4 = new Output();
                _loc_4.writeVarInt(this.deliver.stageid, false);
                _loc_4.writeVarInt(this.deliver.x, false);
                _loc_4.writeVarInt(this.deliver.y, false);
                PluginManager.instance.sendToBufferServer("activity", CMDActivity.IntoBossInstance, _loc_4);
            }
            return;
        }// end function

        public function update(param1:Object, param2:int = 0) : void
        {
            return;
        }// end function

        public function updatebag() : void
        {
            this.removeTween();
            var _loc_1:* = UserData.getBagData("bonus");
            if (ModelProxy.getValue("data", "openday") > 2)
            {
                if (_loc_1 < 200)
                {
                    goumai.clickHandler = new Handler(this.toGm);
                    txt_cost.text = "消耗：<font color=\'#c72514\'>200</font> 礼券";
                    goumai.visible = true;
                    this.tweenMax = TweenMax.to(goumai, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
                }
                else
                {
                    goumai.visible = false;
                    txt_cost.text = "消耗：<font color=\'#53b436\'>200</font> 礼券";
                }
            }
            else
            {
                txt_cost.text = "开服前两天不消耗礼券";
                goumai.visible = false;
            }
            return;
        }// end function

    }
}
